package channel

import (
	"fmt"
	"time"
)

//name: 休眠goroutine的名字
//delay: 休眠时间
func ReportNap(name string, delay int) {
	for i := 0; i < delay; i++ {
		fmt.Println(name, "sleeping")
		time.Sleep(1 * time.Second)
	}
	fmt.Println(name, "wakes up")
}

func Send(myChannel chan string) {
	//Send goroutine先休眠两秒
	ReportNap("sending goroutine", 2)

	//在main goroutine休眠时阻塞发送
	fmt.Println("***sending value***")
	myChannel <- "a"
	fmt.Println("***sending value***")
	myChannel <- "b"
}
